var request = require('./constants').request;

var express = require('express');
var router = express.Router();

router.get('/add-members',function (req,res) {
    var user1 = {
        id:1
    };
    var group = {
        id:1
    };

    var relation = {
        user:user1,
        emailGroupInfo : group
    };
    var relations = [relation];

    console.log("start requst http://localhost:8080/auth/login ");
    request({
        url:'http://localhost:8080/auth/login',
        method:'POST',
        json:true,
        body:{
            "loginId":"blf2",
            "pass":"123456"
        }
    },function (error,res,body) {
        if(!error && res.statusCode == 200){
            console.log("----->login "+body);
            if(body.code == '1') {
                console.log("----------------->login success");
                request({
                    url: 'http://localhost:8080/email-group/add-members',
                    method: 'POST',
                    json: true,
                    headers: {
                        "content-type": "application/json;charset=UTF-8",
                    },
                    body: relations
                }, function (error, response, body) {
                    if (!error && response.statusCode == 200) {
                        console.log("-------->add success");
                        console.log("body = " + JSON.stringify(body));
                    } else {
                        console.error(error);
                    }
                });
            }
        }else{
            console.log("login fail");
            console.error(error);
        }
    });



});

module.exports = router;